package com.renwei.yunlong.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.renwei.yunlong.R;
import com.zyf.fwms.commonlibrary.utils.AutoUtils;

/**
 * 工单 历史 adapter
 *
 * Created by Administrator on 2017/9/11.
 */

public class WorkHistoryPagerAdapter extends RecyclerView.Adapter<WorkHistoryPagerAdapter.WorkHistoryPagerViewHolder>{

    private Context context;
    private LayoutInflater inflater;

    private String[] title = {"张三","李四"};

    private static final int TYPE_TOP = 0x0000;
    private static final int TYPE_NORMAL= 0x0001;

    public WorkHistoryPagerAdapter(Context context){
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public WorkHistoryPagerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_work_history,null);
        AutoUtils.auto(view);
        return new WorkHistoryPagerViewHolder(view);
    }

    @Override
    public void onBindViewHolder(WorkHistoryPagerViewHolder holder, int position) {

        if (getItemViewType(position) == TYPE_TOP) {
            holder.ivView.setImageResource(R.mipmap.dot_cur);
            holder.tvName.setText(title[position]);
            holder.tvType.setText("保存记录");
            holder.tvServiceName.setText("服务对象:宇文泰");
            holder.tvServiceDirectory.setText("服务目录:巡检服务");
            holder.tvProgress.setText("执行进度:2次");
            holder.tvResults.setText("处理结果:下次检查范围应该再扩大些");
            holder.tvDate.setText("2017/10/10");
            holder.tvTime.setText("10:10");
        }else if (getItemViewType(position) == TYPE_NORMAL) {
            holder.ivView.setImageResource(R.mipmap.dot);
            holder.tvName.setText(title[position]);
            holder.tvType.setText("保存记录");
            holder.tvServiceName.setText("服务对象:宇文泰");
            holder.tvServiceDirectory.setText("服务目录:巡检服务");
            holder.tvProgress.setText("执行进度:2次");
            holder.tvResults.setText("处理结果:下次检查范围应该再扩大些");
            holder.tvDate.setText("2017/10/10");
            holder.tvTime.setText("10:10");
        }
    }

    @Override
    public int getItemCount() {
        return title.length;
    }

    @Override
    public int getItemViewType(int position) {
        if (position == 0) {
            return TYPE_TOP;
        }
        return TYPE_NORMAL;
    }

    static class WorkHistoryPagerViewHolder extends RecyclerView.ViewHolder{

        private View itemView;
        private ImageView ivView;
        private TextView tvName;//名称
        private TextView tvType;//类型
        private TextView tvServiceName;//服务名称
        private TextView tvServiceDirectory;//服务目录
        private TextView tvProgress;//执行进度
        private TextView tvResults;//处理结果
        private TextView tvAutograph;//查看
        private TextView tvDate;//日期
        private TextView tvTime;//时间

        public WorkHistoryPagerViewHolder(View view) {
            super(view);
            itemView = view;
            ivView = (ImageView) itemView.findViewById(R.id.iv_view);
            tvName = (TextView) itemView.findViewById(R.id.tv_name);
            tvType = (TextView) itemView.findViewById(R.id.tv_type);
            tvServiceName = (TextView) itemView.findViewById(R.id.tv_service_name);
            tvServiceDirectory = (TextView) itemView.findViewById(R.id.tv_service_directory);
            tvProgress = (TextView) itemView.findViewById(R.id.tv_progress);
            tvResults = (TextView) itemView.findViewById(R.id.tv_results);
            tvAutograph = (TextView) itemView.findViewById(R.id.tv_autograph);
            tvDate = (TextView) itemView.findViewById(R.id.tv_date);
            tvTime = (TextView) itemView.findViewById(R.id.tv_time);
        }
    }
}
